package com.db4o.odbgen.plugins.java.maingenerator.typedxmlschema;

import com.db4o.internal.odbgen.StringUtils;
import com.db4o.odbgen.plugins.xmlschema.Element;

/**
 * 
 * Represents a parameter of an enum constant.
 * When code is generated for the enum, a constructor is built holding each
 * parameter and getters are created for all of them.
 * See also {@link TSEnumValue}. 
 * @author liviug
 */
public class TSEnumParameter implements XmlElement{
    private Element _element;
    private DataType _type;
    private String _name;
    private int _order;

    /**
     * Constructs an enum parameter given it's fields.
     * @param element The corresponding element inside XmlSchema.
     * @param name The name of the parameter.
     * @param order The order of the parameter.
     */
    public TSEnumParameter(
            Element element,
            DataType type,
            String name,
            int order
            ){
        this._element = element;
        this._type = type;
        this._name = name;
        this._order = order;
    }
    
    /**
     * See {@link XmlElement} for details.
     */
    @Override
    public Element getElement() {
        return this._element;
    }
    
    public DataType getType(){
        return this._type;
    }

    public String getName(){
        return this._name;
    }
    
    /**
     * Returns the order of this parameter.
     * The first parameter inside an enum will have order 0.
     * This is used to match the order of the values inside each constant and
     * also the order of parameters within enum's constructor. 
     */
    public int getOrder(){
        return this._order;
    }

    /**
     * Returns a string representing this object.
     * This is used for debug purposes.
     * @param tabs Number of tabs to indent.
     */
    String toString(int tabs) {
        StringBuilder res = new StringBuilder();
        
        res.append(String.format("%sparameter", StringUtils.tabs(tabs)));
        res.append(StringUtils.newLine());

        res.append(String.format("%sname=%s",
                StringUtils.tabs(tabs+1),
                this.getName()
                ));
        res.append(StringUtils.newLine());

        res.append(String.format("%sorder=%s",
                StringUtils.tabs(tabs+1),
                this.getOrder()
                ));
        res.append(StringUtils.newLine());
        
        return res.toString();
    }
}




